//
//  ViewController.m
//  BouncingBalls
//
//  Created by iD Student on 6/28/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
# define GRAVITY -10;
- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    velocity=CGPointMake(10, 3);
    ball=[[UIImageView alloc]init];
    [ball setImage:[UIImage imageNamed:@"ball.png"]];
    [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(move) userInfo:nil repeats:YES];
    [ball setFrame:CGRectMake(140, 140, 20, 20)];
    [self.view addSubview:ball];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    } else {
        return YES;
    }
}
-(void)move{
    ball.center=CGPointMake(ball.center.x+velocity.x, ball.center.y+velocity.y);
    if(ball.center.x>300||ball.center.x<5){
        velocity.x=-velocity.x;
    }
    if (ball.center.y>450||ball.center.x<5) {
        velocity.y=-velocity.y;
       }
    else
        velocity.y=velocity.y-GRAVITY;

}
@end
